package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.Default()
	router.GET("/reader", func(ctx *gin.Context) {
		resp, err := http.Get("https://img2.baidu.com/it/u=1337068678,3064275007&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=750")
		if err != nil || resp.StatusCode != http.StatusOK {
			ctx.Status(http.StatusServiceUnavailable)
			return
		}
		reader := resp.Body
		contentLength := resp.ContentLength
		contentType := resp.Header.Get("Content-Type")
		extraHeaders := map[string]string{
			"Content-Disposition": `attachment; filename="gopher.png"`,
		}
		ctx.DataFromReader(http.StatusOK, contentLength, contentType, reader, extraHeaders)
	})
	router.Run()
}
